use ::libc;
extern "C" {
    fn strchr(_: *const libc::c_char, _: libc::c_int) -> *mut libc::c_char;
    fn strcspn(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_ulong;
    fn strspn(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_ulong;
    fn strlen(_: *const libc::c_char) -> libc::c_ulong;
    fn strcasecmp(_: *const libc::c_char, _: *const libc::c_char) -> libc::c_int;
    fn strncasecmp(_: *const libc::c_char, _: *const libc::c_char, _: libc::c_ulong)
        -> libc::c_int;
    fn xsnprintf(_: *mut libc::c_char, _: size_t, _: *const libc::c_char, _: ...) -> libc::c_int;
}
pub type __u_int = libc::c_uint;
pub type u_int = __u_int;
pub type size_t = libc::c_ulong;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed {
    pub name: *const libc::c_char,
    pub attr: libc::c_int,
}
#[no_mangle]
pub unsafe extern "C" fn attributes_tostring(mut attr: libc::c_int) -> *const libc::c_char {
    static mut buf: [libc::c_char; 512] = [0; 512];
    let mut len: size_t = 0;
    if attr == 0 as libc::c_int {
        return b"none\0" as *const u8 as *const libc::c_char;
    }
    len = xsnprintf(
        buf.as_mut_ptr(),
        ::core::mem::size_of::<[libc::c_char; 512]>() as libc::c_ulong,
        b"%s%s%s%s%s%s%s%s%s%s%s%s%s%s\0" as *const u8 as *const libc::c_char,
        if attr & 0x80 as libc::c_int != 0 {
            b"acs,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x1 as libc::c_int != 0 {
            b"bright,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x2 as libc::c_int != 0 {
            b"dim,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x4 as libc::c_int != 0 {
            b"underscore,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x8 as libc::c_int != 0 {
            b"blink,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x10 as libc::c_int != 0 {
            b"reverse,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x20 as libc::c_int != 0 {
            b"hidden,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x40 as libc::c_int != 0 {
            b"italics,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x100 as libc::c_int != 0 {
            b"strikethrough,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x200 as libc::c_int != 0 {
            b"double-underscore,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x400 as libc::c_int != 0 {
            b"curly-underscore,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x800 as libc::c_int != 0 {
            b"dotted-underscore,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x1000 as libc::c_int != 0 {
            b"dashed-underscore,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
        if attr & 0x2000 as libc::c_int != 0 {
            b"overline,\0" as *const u8 as *const libc::c_char
        } else {
            b"\0" as *const u8 as *const libc::c_char
        },
    ) as size_t;
    if len > 0 as libc::c_int as libc::c_ulong {
        buf[len.wrapping_sub(1 as libc::c_int as libc::c_ulong) as usize] =
            '\0' as i32 as libc::c_char;
    }
    return buf.as_mut_ptr();
}
#[no_mangle]
pub unsafe extern "C" fn attributes_fromstring(mut str: *const libc::c_char) -> libc::c_int {
    let delimiters: [libc::c_char; 4] =
        *::core::mem::transmute::<&[u8; 4], &[libc::c_char; 4]>(b" ,|\0");
    let mut attr: libc::c_int = 0;
    let mut end: size_t = 0;
    let mut i: u_int = 0;
    let mut table: [C2RustUnnamed; 15] = [
        {
            let mut init = C2RustUnnamed {
                name: b"acs\0" as *const u8 as *const libc::c_char,
                attr: 0x80 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"bright\0" as *const u8 as *const libc::c_char,
                attr: 0x1 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"bold\0" as *const u8 as *const libc::c_char,
                attr: 0x1 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"dim\0" as *const u8 as *const libc::c_char,
                attr: 0x2 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"underscore\0" as *const u8 as *const libc::c_char,
                attr: 0x4 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"blink\0" as *const u8 as *const libc::c_char,
                attr: 0x8 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"reverse\0" as *const u8 as *const libc::c_char,
                attr: 0x10 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"hidden\0" as *const u8 as *const libc::c_char,
                attr: 0x20 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"italics\0" as *const u8 as *const libc::c_char,
                attr: 0x40 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"strikethrough\0" as *const u8 as *const libc::c_char,
                attr: 0x100 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"double-underscore\0" as *const u8 as *const libc::c_char,
                attr: 0x200 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"curly-underscore\0" as *const u8 as *const libc::c_char,
                attr: 0x400 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"dotted-underscore\0" as *const u8 as *const libc::c_char,
                attr: 0x800 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"dashed-underscore\0" as *const u8 as *const libc::c_char,
                attr: 0x1000 as libc::c_int,
            };
            init
        },
        {
            let mut init = C2RustUnnamed {
                name: b"overline\0" as *const u8 as *const libc::c_char,
                attr: 0x2000 as libc::c_int,
            };
            init
        },
    ];
    if *str as libc::c_int == '\0' as i32
        || strcspn(str, delimiters.as_ptr()) == 0 as libc::c_int as libc::c_ulong
    {
        return -(1 as libc::c_int);
    }
    if !(strchr(
        delimiters.as_ptr(),
        *str.offset((strlen(str)).wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize)
            as libc::c_int,
    ))
    .is_null()
    {
        return -(1 as libc::c_int);
    }
    if strcasecmp(str, b"default\0" as *const u8 as *const libc::c_char) == 0 as libc::c_int
        || strcasecmp(str, b"none\0" as *const u8 as *const libc::c_char) == 0 as libc::c_int
    {
        return 0 as libc::c_int;
    }
    attr = 0 as libc::c_int;
    loop {
        end = strcspn(str, delimiters.as_ptr());
        i = 0 as libc::c_int as u_int;
        while (i as libc::c_ulong)
            < (::core::mem::size_of::<[C2RustUnnamed; 15]>() as libc::c_ulong)
                .wrapping_div(::core::mem::size_of::<C2RustUnnamed>() as libc::c_ulong)
        {
            if end == strlen(table[i as usize].name) {
                if strncasecmp(str, table[i as usize].name, end) == 0 as libc::c_int {
                    attr |= table[i as usize].attr;
                    break;
                }
            }
            i = i.wrapping_add(1);
        }
        if i as libc::c_ulong
            == (::core::mem::size_of::<[C2RustUnnamed; 15]>() as libc::c_ulong)
                .wrapping_div(::core::mem::size_of::<C2RustUnnamed>() as libc::c_ulong)
        {
            return -(1 as libc::c_int);
        }
        str = str.offset(
            end.wrapping_add(strspn(str.offset(end as isize), delimiters.as_ptr())) as isize,
        );
        if *str as libc::c_int == '\0' as i32 {
            break;
        }
    }
    return attr;
}
